<?php ob_start(); ?>
<style>
    .title-body-content {
        color: #A0002A;
        font-size: 17px;
        font-weight: bold;
        height: auto;
        margin: 0 0 0;
        padding: 0;
        text-align: center;
        width: 100%;
    }
    .clearfix:after {
        clear: both;
        content: ".";
        display: block;
        font-size: 0;
        height: 0;
        visibility: hidden;
    }
    .wrapper-content-body {
        background-color: White;
        height: auto;
        margin: 0 0 60px;
        padding: 0 16px 0;
        width: 96.8%;
    }
    .wrapper-form-account-resume {
        height: auto;
        margin: 20px 60px 0;
        text-align: left;
        width: auto;
    }
    .wrapper-insurance-type-page4 {
        margin: 8px 0 0;
    }
    .clearfix {
        display: block;
    }
    .wrapper-rein-page4 {
        margin: 8px 0 0;
    }
    .wrapper-insurance-type-page4 {
        margin: 8px 0 0;
    }
    .wrapper-ori-insurer-page4 {
        margin: 8px 0 0;
    }
    .wrapper-rate-page4 {
        margin: 8px 0 0;
    }
    .wrapper-gross-pre-page4 {
        margin: 8px 0 0;
    }
    .wrapper-rate-page4 {
        margin: 8px 0 0;
    }
    .wrapper-gross-pre-page4 {
        margin: 8px 0 0;
    }
    .wrapper-gross-pre-page4 {
        margin: 8px 0 0;
    }
    .wrapper-payment-schedule {
        height: auto;
        margin: 20px 0 0;
        width: auto;
    }
    .size-span {
        display: inline-block;
        vertical-align: top;
        width: 135px;
    }
    .tbl-payment {
        height: auto;
        margin: 20px 0;
        table-layout: fixed;
        width: 98.6%;
    }
    .wrapper-payment-schedule {
        height: auto;
        margin: 20px 0 0;
        width: auto;
    }
    .wrapper-content-payment-schedule {
        height: auto;
        width: auto;
    }
    .tbl-payment tr {
        height: auto;
        padding: 5px;
    }
    .tbl-payment-title {
        font-weight: bold;
    }
    .tbl-payment tr td {
        height: auto;
        padding: 5px;
    }
</style>
<div class="header clearfix">
    <div class="head-logo">
        <?php echo $this->Html->image('/img/aih/ARBL FULL Logo Letterhead Footer JPG r.jpg'); ?>
    </div>
    <!-- HTML for menu-bottom-header-->
</div>
<!-- HTML-Body-Web-->
<div class="wrapper-body clearfix">
    <div class="wrapper-content-body clearfix">
        <div>
            <div style="float: left; width:650px; padding-left: 60px; position: relative; font-weight: bold">
                <?php echo $market['Market']['name']; ?><br />
                <?php echo $market['Market']['address']; ?>
                <div class="" style="width:250px; text-align:right; margin:10px 0; float: right; position: absolute; bottom: 0; right: 0">Dated <?php echo date('jS M Y', strtotime($this->request->data['Accountresume']['date'])); ?></div>
            </div>
        </div>
        <div style="clear: both"></div>
        <div class="title-body-content"><?php echo $title_for_layout; ?> <?php echo $this->request->data['Accountresume']['refid_edit']; ?></div>
        <div class="wrapper-form-account-resume clearfix">
            <div class="wrapper-insurance-type-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Type'); ?> :</b></span>
                <?php echo $insurancetype['Insurancetype']['name']; ?>
            </div>
            <div class="wrapper-rein-page4 clearfix">
                <table cellspacing="0" cellpadding="0" border="0">
                    <tr>
                        <td style="text-align:left; vertical-align:top">
                            <span class="size-span" style="width:200px"><b><?php echo __('Reinsured'); ?> :</b></span>
                        </td>
                        <td style="text-align:left">
                            <?php
                            echo '<div class="contactField" style="text-align:left">';
                            echo '   <span class="size-span" style="width: 260px; float:left">';
                            echo '       <b>' . $this->request->data['Accountresume']['reinsured'] . '</b>';
                            echo '   </span>';
                            echo '</div>';
                            ?>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="wrapper-ori-insurer-page4 clearfix">
                <table cellspacing="0" cellpadding="0" border="0">
                    <tr>
                        <td style="text-align:left; vertical-align:top">
                            <span class="size-span" style="width:200px"><b><?php echo __('Original Insured'); ?> :</b></span>
                        </td>
                        <td style="text-align:left">
                            <?php
                            echo '<div class="contactField" style="text-align:left">';
                            echo '   <span class="size-span" style="width: 260px; float:left">';
                            echo '       <b>' . $this->request->data['Accountresume']['original_insured'] . '</b>';
                            echo '   </span>';
                            echo '</div>';
                            ?>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="wrapper-insurance-type-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Period of cover'); ?> :</b></span>
                <b>
                    <?php
                    $temp = round($this->request->data['Accountresume']['total_days'] / 30);
                    if ($temp < 1) {
                        echo $this->request->data['Accountresume']['total_days'];
                        echo ' day' . ($this->request->data['Accountresume']['total_days'] > 1 ? 's' : '');
                    } else {
                        echo $temp . 'month' . ($temp > 1 ? 's' : '');
                    }
                    ?>
                    with effect from 
                    <?php echo date('jS M Y', strtotime($this->request->data['Accountresume']['from_date'])); ?>
                </b>
            </div>
            <div class="wrapper-insurance-type-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Insurance Type Detail'); ?> :</b></span>
                <b>
                    <?php echo $this->request->data['Accountresume']['insurancetype_detail']; ?>
                </b>
            </div>
            <div class="wrapper-sum-insured-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Sum Insured / agreed value'); ?> :</b></span>
                <b><?php echo $this->request->data['Accountresume']['currency']; ?> <?php echo number_format($this->request->data['Accountresume']['sum_insured'], 2); ?></b>
            </div>
            <div class="wrapper-rate-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Rate'); ?> :</b></span>
                <b><?php echo $this->request->data['Accountresume']['rate']; ?> %</b>
            </div>
            <div class="wrapper-gross-pre-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('100% Gross Premium'); ?> :</b></span>
                <b><?php echo $this->request->data['Accountresume']['currency']; ?> <?php echo number_format($this->request->data['Accountresume']['gross_premium'], 2); ?></b>
            </div>
            <!-- start new version -->
            <div class="wrapper-rate-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Order Hereon'); ?> :</b></span>
                <b>
                    <?php
                    echo ($sub_order_hereon == '') ? 'N/A' : $sub_order_hereon . ' %';
                    ?>
                </b>
            </div>
            <div class="wrapper-rate-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Brokerage'); ?> :</b></span>
                <b>
                    <?php 
                    echo ($brokerage_rate == '') ? 'N/A' : $brokerage_rate . ' %';
                    ?>
                </b>
            </div>
            <div class="wrapper-gross-pre-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Client Discount'); ?> :</b></span>
                <b><?php echo $this->request->data['Accountresume']['client_discount']; ?> %</b>
            </div>
            <div class="wrapper-gross-pre-page4 clearfix">
                <span class="size-span" style="width:200px"><b><?php echo __('Order Premium'); ?> :</b></span>
                <b><?php echo $this->request->data['Accountresume']['currency']; ?> <?php echo number_format($this->request->data['Accountresume']['order_premium'], 2); ?></b>
            </div>

            <?php
            $html_to_markets = '';
            $html_payment_schedule_infos = '
            <div class="wrapper-gross-pre-page4 clearfix">
                <span class="size-span" style="width:500px"><b>' . __('Installments') . ' :</b></span>
            </div>
            <div class="wrapper-payment-schedule clearfix" style="margin-top:0">
                <div class="wrapper-content-payment-schedule clearfix">
                    <table cellspacing="0" cellpadding="0" border="0" style="margin-bottom:0" class="tbl-payment">';

            $i = 1;
            foreach ($premium_closings as $v) {
                $th = '<span style="font-weight:bold">' . $i . ' <sup>th</sup></span>';
                if ($i == 1) {
                    $th = '<span style="font-weight:bold">' . $i . ' <sup>st</sup></span>';
                } else if ($i == 2) {
                    $th = '<span style="font-weight:bold">' . $i . ' <sup>nd</sup></span>';
                } else if ($i == 3) {
                    $th = '<span style="font-weight:bold">' . $i . ' <sup>rd</sup></span>';
                }
                $html_to_markets = '
                <div class="wrapper-gross-pre-page4 clearfix">
                    <span class="size-span" style="width:200px"><b>' . __('Nett Premium due to') . ' ' . $v[0] . '</b></span>
                    <b>' . $this->request->data['Accountresume']['currency'] . ' ' . number_format($total, 2) . '</b>
                </div>';
                $html_payment_schedule_infos .= '
                        <tr class="tbl-payment-title striped">
                            <td class="td-from-producing-broker" width="360" style="text-align:left">' .
                        $th .
                        '<b> on or before ' .
                        date('jS M Y', strtotime($v[2])) .
                        '</b>
                            </td>
                            <td class="td-to-asurasi" style="text-align:left">
                                <b>' .
                        $this->request->data['Accountresume']['currency'] . ' ' . number_format($v[3], 2) .
                        '</b>
                            </td>
                        </tr>';
                $i++;
            }
            $html_payment_schedule_infos .= '
                    </table>
                </div>
            </div>';
            echo $html_to_markets, $html_payment_schedule_infos;
            ?>
            <!-- end new version -->
            <div class="wrapper-payment-schedule clearfix">
                <div class="wrapper-content-payment-schedule clearfix">
                    <table cellspacing="0" cellpadding="0" border="0" style="margin-bottom:0" class="tbl-payment">
                        <tr class="tbl-payment-title striped">
                            <td class="td-from-producing-broker" width="360" style="text-align:left; font-weight:normal;">
                                Yours sincerely,<br />
                                <br />
                                <br />
                            </td>
                            <td class="td-to-asurasi" style="text-align:left"></td>
                        </tr>
                        <tr class="tbl-payment-title striped">
                            <td class="td-from-producing-broker" width="360" style="text-align:left; font-weight:normal;">
                            </td>
                            <td class="td-to-asurasi" style="text-align:left"></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <?php
    $HtmlCode = ob_get_contents();
    ob_end_flush();
    $HtmlCode1 = str_replace('/aih/img/aih/ARBL FULL Logo Letterhead Footer JPG r.jpg', 'img/ARBL FULL Logo Letterhead Footer JPG r.jpg', $HtmlCode);
    $file = '/home/johnso28/public_html/aihreinsurance.com/dompdf/aih/premium_closing.html';
    file_put_contents($file, $HtmlCode1);
    ?>
    <div class="wrapper-button-form clearfix">
        <div class="button-form clearfix">
            <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/dompdf/dompdf.php?base_path=aih/&input_file=premium_closing.html&paper=a4">Download PDF</a>
        </div>
    </div>
</div>